﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Webcar.BLL;
using BusinessEntity;

namespace Webcar.Car
{
    public partial class GpsTJ : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.IsPostBack) return;
            DropDownListManager.BindDropDownDW(this.ddlDept);
        }

        protected void ddlDept_SelectedIndexChanged(object sender, EventArgs e)
        {
            string dept = this.ddlDept.SelectedValue;
            GPS_TJEntity entity = new GPS_TJEntity();
            entity.DEPT_CODE = dept;
            entity.Retrieve();
            
            this.cjdw.Text = entity.CJDW;
            this.cjdw_lxr.Text = entity.CJDW_LXR;
            this.cjdw_dh.Text = entity.CJDW_DH;
            this.gps_num.Text = entity.GPS_NUM.ToString();
            this.tbr.Text = entity.TBR;
            this.tbr_lxdh.Text = entity.TBR_LXDH;
            this.tbrq.Text = entity.TBRQ.ToString();
            this.tbNote.Text = entity.NOTE;
            
            if (!entity.IsPersistent)
            {
                this.tbrq.Text = DateTime.Now.ToString();
                this.tbr.Text = CurrentUser.GetLoginUserName();
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.ddlDept.SelectedValue))
            {
                this.lblError.Text = "请选择单位。";
                return;
            }
            if (string.IsNullOrEmpty(this.ddlDept.SelectedValue))
            {
                this.lblError.Text = "请选择单位。";
                return;
            }
            if (string.IsNullOrEmpty(this.cjdw.Text))
            {
                this.lblError.Text = "请输入承建单位。";
                return;
            }
            if (string.IsNullOrEmpty(this.cjdw_lxr.Text))
            {
                this.lblError.Text = "请输入承建单位联系人。";
                return;
            }
            if (string.IsNullOrEmpty(this.gps_num.Text))
            {
                this.lblError.Text = "请输入GPS数量。";
                return;
            }

            GPS_TJEntity entity = new GPS_TJEntity();
            entity.DEPT_CODE = this.ddlDept.SelectedValue;
            entity.Retrieve();
            entity.CJDW = this.cjdw.Text;
            entity.CJDW_LXR =this.cjdw_lxr.Text ;
             entity.CJDW_DH =this.cjdw_dh.Text;
            entity.GPS_NUM = int.Parse(this.gps_num.Text) ;
            entity.TBR =this.tbr.Text  ;
             entity.TBR_LXDH= this.tbr_lxdh.Text ;
             entity.TBRQ = DateTime.Now;
            entity.NOTE =this.tbNote.Text ;
            entity.Save();
            this.Alert("保存成功！");
        }
    }
}
